<!-- 首页 -->
<template>
  <div class="dashboard-editor-container">

    <!-- 如果不是物流公司用户 -->
    <div v-if="userType !== $store.state.constants.userType_company">
      <!-- 基础信息数量统计 -->
      <panel-group />

      <!-- 快捷功能 -->
      <connect-box/>
    </div>

    <!-- 物流公司用户 -->
    <div v-else>
      <!-- 订单进行 -->
      <order-steps/>

      <!-- 添加或修改物流公司对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false">
        <company-form :mode="mode" :companyId="companyId" @close="close" />
      </el-dialog>
    </div>

    <!-- 系统公告 -->
    <div style="margin-top: 15px;">
      <notice-group/>
    </div>

  </div>
</template>

<script>
import { getCompanyByUserId } from '@/api/tws/company';
import PanelGroup from './dashboard/PanelGroup';
import ConnectBox from './dashboard/ConnectBox';
import OrderSteps from './dashboard/OrderSteps';
import NoticeGroup from './dashboard/NoticeGroup';
import CompanyForm from '@/components/CompanyForm/index';

export default {
  name: 'Index',
  components: {
    PanelGroup,
    ConnectBox,
    OrderSteps,
    NoticeGroup,
    CompanyForm
  },
  data() {
    return {
      userType: '',
      title: '请完善信息',
      mode: '1',
      companyId: null,
      open: false
    }
  },
  created() {
    this.userType = this.$store.state.user.type;
    this.getCert();
  },
  methods: {
    // 货源方用户查询是否认证
    getCert() {
      // 货源方用户
      if(this.userType == this.$store.state.constants.userType_company) {
        getCompanyByUserId(this.$store.state.user.userId).then(res => {
          if(res.code == 200) {
            if(!res.data) {
              this.open = true;
              this.mode = '';
              this.companyId = null;
              setTimeout(() => {
                this.mode = '1';  // 新增模式
              })
            } else {
              // 如果未认证或认证失败
              if(res.data.isCert == this.$store.state.constants.isCert_wrz || res.data.isCert == this.$store.state.constants.isCert_rzsb) {
                this.open = true;
                this.mode = '';
                this.companyId = null;
                setTimeout(() => {
                  this.companyId = res.data.id;
                  this.mode = '2';  // 修改模式
                })
                if(res.data.isCert == this.$store.state.constants.isCert_rzsb) {
                  this.title = '审核未通过, 请重新提交审核。原因：' + res.data.failReason;
                }
              }
            }
          }
        })
      }
    },
    close() {
      this.open = false;
    }
  }
}
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

.colmargin {
  margin: 0 0 20px;
}
@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}

.ivu-pl-8 {
  margin-left: 8px;
  font-size: 14px;
}

  .col-style{
    background: white;
    font-size: 25px;
    text-align: center;
  }
</style>
